﻿#region

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogicLayer;
using BusinessObjects;

#endregion

namespace FastTrackCabService.AdminPanel
{
    public partial class DriverFullView : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int staffId;
                if (int.TryParse(Request.QueryString["staffId"], out staffId))
                {
                    LoadDetailsView(staffId);
                }
                else
                {
                    Response.Redirect("Drivers.aspx");
                }
            }
        }

        private void LoadDetailsView(int staffId)
        {
            Staff staff = StaffBLL.GetStaffById(staffId);
            Driver d = DriverBLL.GetAllDrivers().Single(dr => dr.StaffId == staffId);
            Driver driver = new Driver(staff)
            {
                LicenseNo = d.LicenseNo,
                Availability = d.Availability
            };

            DetailsView1.DataSource = new List<Driver> {driver};
            DetailsView1.DataBind();
        }

        protected void DetailsView1_OnModeChanging(object sender, DetailsViewModeEventArgs e)
        {
            Response.Redirect("EditDriverForm.aspx?staffId=" + Request.QueryString["staffId"]);
        }
    }
}